package org.brisling.medical.service;

import java.util.List;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.domain.RetDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.medical.domain.MedicalPathwayPatientConclusion;
import org.brisling.medical.queryService.QueryMedicalPathwayPatientConclusion;
import org.brisling.medical.repository.MedicalPathwayPatientConclusionRepo;
import org.brisling.medical.service.base.BaseMedicalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequestMapping("/MedicalPathwayPatientConclusion")
/**
 * 
 * <p>Title: MedicalPathwayPatientService</p>
 * <p>Description: 指标JPA 服务类</p>
 * <p>Company: tongking</p> 
 * @author jackson wang
 * @since  1.0
 * @version 1.0
 * @date 2016年5月18日 下午9:45:34
 */
public class MedicalPathwayPatientConclusionService extends BaseMedicalService<MedicalPathwayPatientConclusion>{
	
	@SuppressWarnings("unused")
	@Autowired
	private MedicalPathwayPatientConclusionRepo baseRepo;
	
	@Autowired
	private QueryMedicalPathwayPatientConclusion qryMedicalPathwayPatientConclusion;
	
	public MedicalPathwayPatientConclusionService(){
		this.moduleName = ConstSysParam.MODULE_PATHWAY_PATIENT_CONCLUSION;
	}
	
	/**
	 * 获取业务主页面 
	 * @return
	 */
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return getBizMainPage();
	}
	
	/**
	 * 获取业务编辑页面
	 * @return
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return getBizEditPage();
	}
	
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getListDomain.action")
	public ListDomain<MedicalPathwayPatientConclusion> getListDomain(
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
				
		return super.getPagedList(page, rows);
			
	}
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getList.action")
	public List<MedicalPathwayPatientConclusion> getPagedListRows(
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
		
			return super.getAll(page,rows,getSort(sort));
			
	}
	
	/**
	 * 删除记录,单条或批量删除记录,id不为空，执行单条删除，id为空且ids不为空，执行批量删除
	 * @param id	待删除的单条记录id
	 * @param ids	待删除的多条记录id，以','分隔
	 * @return
	 */
	@RequestMapping("/del.action")
	public RetDomain delRow(@RequestParam(value="id",required=false) Long id,@RequestParam(value="ids",required=false) String ids){
				
		return super.delRows(id, ids);		 
	}
	
	/**
	 * 删除记录,单条或批量删除记录,id不为空，执行单条删除，id为空且ids不为空，执行批量删除
	 * @param id	待删除的单条记录id
	 * @param ids	待删除的多条记录id，以','分隔
	 * @return
	 */
	@RequestMapping("/flowDel.action")
	public RetDomain delFlowRow(@RequestParam(value="id",required=false) Long id,@RequestParam(value="ids",required=false) String ids){
		
			return delRow(id,ids);
		
	}
	
	
	/**
	 * 删除组织节点
	 * @param id
	 */
	@RequestMapping("/save.action")
	public MedicalPathwayPatientConclusion save(@RequestBody String body){
		MedicalPathwayPatientConclusion obj = bodyToObj(body, MedicalPathwayPatientConclusion.class);		
		
		return this.save(obj);
	}
	
	/**
	 * 删除组织节点
	 * @param id
	 */
	
	public MedicalPathwayPatientConclusion save(MedicalPathwayPatientConclusion indi){
				
		MedicalPathwayPatientConclusion obj= super.save(indi);
		if(obj!=null && obj.getId()!=null)
			return qryMedicalPathwayPatientConclusion.getOne(obj.getId());
		
		return null;
	}
	
	public List<MedicalPathwayPatientConclusion> saveAllList(List<MedicalPathwayPatientConclusion> pram){
		for(int i = 0; i < pram.size(); i++){
			save(pram.get(i));
			System.out.println("\n\n\nadd one\n\n\n#");
		}
		return pram;
		
	}
	
	public List<MedicalPathwayPatientConclusion> autoMonitor(Integer year, Integer month){
		List<MedicalPathwayPatientConclusion> lists = qryMedicalPathwayPatientConclusion.autoMonitor(year, month);
		saveAllList(lists);
		return lists;
	}
//	public List<MedicalPathwayPatientConclusion> uploadExcelFile(String path) throws IOException, Exception{
//		List<MedicalPathwayPatientConclusion> ret = qryMedicalPathwayPatientConclusion.readExcelData(path);
//		saveAllList(ret);
//		return ret;
//	}
}
